package day_2022_1_to_2.day16;

//1、字符串逆置，如 "I am a student" 逆置为 "student a am I" 。

import java.util.Scanner;

public class Day8_1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入字符串：");
        String string2 = scanner.nextLine();
        System.out.println(reverseSentence(string2));
    }

    public static String reverseSentence(String str) {
        String[] str1=str.split(" ");
        String str2="";
        for (int i = str1.length-1; i >-1 ; i--) {
            str2+=str1[i];
            if(i!=0){
                str2+=" ";
            }
        }
        return str2;
    }
}
